/*jslint node:true*/
'use strict';
var http = require('http');
var querystring = require('querystring');
var postHTML = '<html><head>' +
    '<meta charset="utf-8"><title>菜鸟教程 Node.js 实例</title></head>' +
    '<body><form method="post">' +
    '网站名：<input name="name" /><br />' +
    '网站URL：<input name="url" /><br />' +
    '<input type="submit" />' +
    '</form></body></html>';

http.createServer(function (request, response) {
    var post = '';
    request.on('data', function (chunk) {
        post += chunk;
    });
    request.on('end', function () {
        post = querystring.parse(post);
        
        if (post.name && post.url) {
            response.writeHead(200, {'Content-Type': 'text/plain; charset=utf-8'});
            response.write('网站名：' + post.name);
            response.write('\n');
            response.write('网站URL：' + post.url);
        } else {
            response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
            response.write(postHTML);
        }
        response.end();
    });
}).listen(8888);
console.log('服务器开始运行，正在8888端口监听');